package com.keke.myblogv1.girlfriend.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.keke.myblogv1.common.result.ResponseResult;
import com.keke.myblogv1.girlfriend.dto.QueryMyBlogGirlfriendByPageDTO;
import com.keke.myblogv1.girlfriend.entity.MyBlogGirlfriend;
import com.keke.myblogv1.girlfriend.service.MyBlogGirlfriendService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author Derrick
 * @since 2022-07-31
 */
@RestController
@RequestMapping("/girlfriend")
public class MyBlogGirlfriendController {

    @Resource
    private MyBlogGirlfriendService myBlogGirlfriendService;

    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public ResponseResult<List<MyBlogGirlfriend>> getGirlfriendList() {
        List<MyBlogGirlfriend> girlfriendList = null;
        try {
            girlfriendList = myBlogGirlfriendService.getGirlfriendList();
        } catch (Exception e) {
            e.printStackTrace();
            return ResponseResult.error();
        }
        return ResponseResult.success(girlfriendList);
    }

    @RequestMapping(value = "",method = RequestMethod.GET)
    public ResponseResult<Page<MyBlogGirlfriend>> getGirlfriendListByPage(QueryMyBlogGirlfriendByPageDTO queryMyBlogGirlfriendByPageDTO){
        Page<MyBlogGirlfriend> girlfriendListByPage = null;
        try {
            girlfriendListByPage = myBlogGirlfriendService.getGirlfriendListByPage(queryMyBlogGirlfriendByPageDTO);
        } catch (Exception e) {
            e.printStackTrace();
            return ResponseResult.error();
        }
        return ResponseResult.success(girlfriendListByPage);
    }

    @RequestMapping(value = "/insert",method = RequestMethod.POST)
    public ResponseResult insertGirlfriend(@RequestBody MyBlogGirlfriend myBlogGirlfriend){
        boolean result = false;
        try{
            result = myBlogGirlfriendService.insertGirlfriend(myBlogGirlfriend);
        }catch (Exception e){
            e.printStackTrace();
            return ResponseResult.error();
        }
        if(result){
            return ResponseResult.success();
        }else{
            return ResponseResult.error();
        }
    }

    @RequestMapping(value = "/update",method = RequestMethod.POST)
    public ResponseResult updateGirlfriend(@RequestBody MyBlogGirlfriend myBlogGirlfriend){
        boolean result = false;
        try{
            result = myBlogGirlfriendService.updateGirlfriend(myBlogGirlfriend);
        }catch (Exception e){
            e.printStackTrace();
            return ResponseResult.error();
        }
        if(result){
            return ResponseResult.success();
        }else{
            return ResponseResult.error();
        }
    }

    @RequestMapping(value = "/delete",method = RequestMethod.POST)
    public ResponseResult deleteGirlfriend(@RequestBody MyBlogGirlfriend myBlogGirlfriend){
        boolean result = false;
        try{
            result = myBlogGirlfriendService.deleteGirlfriend(myBlogGirlfriend);
        }catch (Exception e){
            e.printStackTrace();
            return ResponseResult.error();
        }
        if(result){
            return ResponseResult.success();
        }else{
            return ResponseResult.error();
        }
    }


}
